package com.elinkway.infinitemovies.http.parser;

import com.apkfuns.logutils.LogUtils;
import com.elinkway.infinitemovies.utils.UpgradeInfo;

import org.json.JSONObject;

/**
 * Author: liuxiaojiang(xiao)
 * Date: 2017-06-07
 * Time: 15:24
 * Description: app升级解析
 */
public class UpgradeInfoParser extends LVideoMobileParser<UpgradeInfo> {

    private static final String UPGRADE = "upgrade";
    private static final String UPGRADE_DATA = "upgradeData";
    private static final String VERSION = "version";
    private static final String LINK = "link";
    private static final String TYPE = "type";
    private static final String DESC = "desc";

    @Override
    public UpgradeInfo parse(JSONObject data) throws Exception {
        LogUtils.d("upgrade parser data is " + data);
        UpgradeInfo upgradeInfo = new UpgradeInfo();
        boolean upgrade = data.optBoolean(UPGRADE);
        upgradeInfo.setUpgrade(upgrade);
        if (upgrade) {
            JSONObject upgradeData = data.optJSONObject(UPGRADE_DATA);
            if(upgradeData != null){
                upgradeInfo.setVersion(upgradeData.optString(VERSION));
                upgradeInfo.setType(upgradeData.optString(TYPE));
                upgradeInfo.setLink(upgradeData.optString(LINK));
                upgradeInfo.setDesc(upgradeData.optString(DESC));
            }
        }
        return upgradeInfo;
    }
}
